Skip to content
This repository has been archived by the owner on Jan 4, 2020. It is now read-only.

修正addAll()的隐患bug #475

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

zhiqiangbuxi
Copy link

image

  • 描述:批量循环写入时,出现主键不连续的情况,跳跃增长(请自行测试)
  • 紧急程度:严重
  • 原因:innodb中insert操作分为三种情况:Simple inserts,Bulk inserts,Mixed-mode inserts,其中Simple inserts这种MySQL引擎提前知道要插入的行数,而后两种并不知道,针对三种情况mysql提供, innodb_autoinc_lock_mode 配置参数,设置为0,1(默认)或2,分别为 “ 传统的 ”,“ 连续的 ”, “ 交错 ”锁定模式。在官方默认的insert into table() (select *) union all (select *).... 属于Bulk inserts所以会造成主键不连续,反之insert into table() values(),().....属于Simple inserts则不会。除非手动修改innodb_autoinc_lock_mode=0,也就是采用传统锁模式,所有insert操作都要申请auto-inc锁。
  • 文献:http://dev.mysql.com/doc/refman/5.5/en/innodb-auto-increment-handling.html
  • PS:希望官方测试后,完善该BUG

@liu21st
Copy link
Member

liu21st commented Sep 30, 2016

这么设计就是为了通用化考虑 你这种有些数据库没法支持

@zhiqiangbuxi
Copy link
Author

原来这样,看来只有在自己的项目修改了,但是addAll()这个导致主键不连续这也是个大坑。

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants